package cn.yqm.frame.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import cn.yqm.frame.xmlParse.ActionXmlUtil;
import cn.yqm.frame.xmlParse.XmlBeans.XmlBean;

public class SCListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		System.out.println("-----------容器销毁------------");
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		System.out.println("-----------容器初始化开始------------");
		//解析xml并封装成xmlbean对象
		ServletContext sc = arg0.getServletContext();
		String xmlPath = sc.getInitParameter("xmlConfig");
		
		XmlBean xmlBean = ActionXmlUtil.parseXml(sc.getRealPath("/")+xmlPath);
		
		if (xmlBean == null) {
			System.out.println("----------容器初始化失败-----------");
			return;
		}
		//放到全局作用遇中
		sc.setAttribute("xmlConfig", xmlBean);
		System.out.println("-----------容器初始化完成------------");
	}

}
